package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.clientCenter.Enum.ProcessStateEnum;
import com.koron.css2.newProjectCenter.Enum.PjCollectionPaymentStatus;
import com.koron.css2.newProjectCenter.bean.PjCollection;
import com.koron.css2.newProjectCenter.bean.query.PjCollectionQuery;
import com.koron.css2.newProjectCenter.mapper.PjCollectionMapper;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.workflow.AbstractProcessInterface;
import com.koron.css2.workflow.ProcessInterface;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 工程报装-工程收款-工作流回调接口
 *
 * @author 朱超
 * @since 2022-01-19 10:44:39
 */
@Deprecated
public class PjCollectionProcess extends AbstractProcessInterface {

    @Override
    public MessageBean<?> before(SessionFactory factory, UserInfoBean userInfo, String billId, String fromNodeCode, int operation) {
        try {
            PjCollectionMapper pjCollectionMapper = factory.getMapper(PjCollectionMapper.class);

            // 1. 如果是通过
            if (operation == ProcessInterface.OPERATION_AGREE && fromNodeCode.equals(ProcessStateEnum.PROCESSING.getState())) {
                // 2. 根据id查询单条数据
                PjCollectionQuery pjCollectionQuery = new PjCollectionQuery();
                pjCollectionQuery.setId(billId);
                PjCollection pjCollection = pjCollectionMapper.getSingle(pjCollectionQuery);
                // 3.  status=1-可收款
                pjCollection.setStatus(PjCollectionPaymentStatus.COLLECTION.getStatus());
                // 3.1 updateTime,updateAccount,updateName
                pjCollection.setUpdateInfo(userInfo);
                pjCollectionMapper.update(pjCollection);
                // 4. 返回结果
                return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "工程收款提交成功", null);
            } else {
                String failMessage = fromNodeCode + "- 该节点未在并户工作流中配置，请联系管理员!";
                return MessageBean.create(Constant.MESSAGE_INT_FAIL, failMessage, void.class);
            }
        } catch (Exception e) {
            logger.error("工程收款提交失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "工程收款提交成功", null);
        }
    }

}
